import pandas as pd
import yaml

from yaml import SafeLoader

from datareport.api import ImageUtil
from datareport.api.DataSource import DataSource
from datareport.api.annotation.Font import Font
from datareport.api.enum.ColorEnum import ColorEnum
from datareport.impl.paragraph.base.BaseParagraph import BaseParagraph
from datareport.api.annotation.Style import style


@style()
class KaiZhanQingKuang_pingci_erji_40(BaseParagraph):
    """
    组织生活开展频次-二级党支部情况
    """
    decrease=40

    def __init__(self):
        super().__init__()
        self.text = '''2 、二级党组织月平均开展情况'''
        self.sort = 30
        self.section = 12

    def plot(self, df, plt):
        pass

    def getData(self, result):
        pass

    def start(self, conn, year, plt):
        df=pd.read_sql('''select left(partyOrgName,2) partyOrgName,round(count(1)/12,1) avg from(
        select partyOrgName from t_meetingplan where year(createTime)={} 
        and activityId in (select activityId from t_meetingrecord)
        )new group by partyOrgName
        '''.format(year),con=conn)
        self.image=ImageUtil.plot(df,ylable='月平均开展频次',xlable='二级党组织')

if __name__ == '__main__':
    with open('D:\work\sanhuiyike\datareport\config.yaml', encoding='utf-8') as f:
        data = yaml.load(f, Loader=SafeLoader)
    con=DataSource(data['datasource']).conn
    KaiZhanQingKuang_pingci_erji_38().start(con,2023,'')
